package com.example.service;

import com.example.dao.*;
import com.example.util.ToDouble;
import com.example.util.ToDouble2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.*;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.lang.reflect.Type;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */

@Service
public class NovelService {

    @Autowired
    MongoTemplate mongoTemplate;

    public void find() {
        //Query query=new Query();
        List<Novel> novelList = mongoTemplate.findAll(Novel.class, "novel");
        novelList.forEach(System.out::println);
    }

    public void add() {
        Query query = new Query();
        List<Novel> novelList = mongoTemplate.find(query, Novel.class);
        List<Novel2> novel2List = new ArrayList<>();
        for (Novel novel : novelList) {
            Novel2 novel2 = new Novel2();
            novel2.set_id(novel.get_id());
            novel2.setNovelcount(ToDouble.convertToDouble(novel.getNovelcount()));
            novel2.setNovelname(novel.getNovelname());
            novel2.setTotaltui(ToDouble.convertToDouble(novel.getTotaltui()));
            novel2.setWeektui(ToDouble.convertToDouble(novel.getWeektui()));
            novel2.setAuthor(novel.getAuthor());
            novel2.setType(novel.getType());
            novel2.setState(novel.getState());
            novel2.setWriteday(ToDouble.convertToDouble(novel.getWriteday()));
            novel2.setLeiji(ToDouble.convertToDouble(novel.getLeiji()));
            novel2.setTotalnovel(ToDouble.convertToDouble(novel.getTotalnovel()));
            novel2.setMonthvote(ToDouble.convertToDouble(novel.getMonthvote()));
            novel2.setReward(ToDouble.convertToDouble(novel.getReward()));
            mongoTemplate.insert(novel2, "novel2");

        }
    }

    public List<Novel2> totaltui() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.with(Sort.by("totaltui").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List<Novel2> reward() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.with(Sort.by("reward").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List writeday() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.with(Sort.by("writeday").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List state() {
        StateDto stateDto = new StateDto();
        StateDto stateDto1 = new StateDto();
        Query query = new Query();
        int a = 0;
        int b = 0;
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class, "novel2");
        List<StateDto> list = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            novel2.setState(ToDouble2.convertToDouble(novel2.getState()));
            if (novel2.getState().equals("完本")) {
                a++;
            } else {
                b++;
            }
        }
        stateDto.setValue(a);
        stateDto.setName("完本");
        stateDto1.setValue(b);
        stateDto1.setName("连载");

        list.add(stateDto);
        list.add(stateDto1);
        return list;
    }

    public List leiji() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.with(Sort.by("leiji").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List monthvote() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.with(Sort.by("monthvote").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List week() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.with(Sort.by("weektui").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }


    public List type1() {
        TypeDto typeDtos[] = new TypeDto[12];
        Query query = new Query();
        String str[] = new String[12];
        int a[] = new int[12];
        for (int i = 0; i < 12; i++) {
            typeDtos[i] = new TypeDto();
            a[i] = 0;
        }
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class, "novel2");
        List<TypeDto> list = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            if (novel2.getType().equals("都市")) {
                a[0]++;
                str[0] = novel2.getType();
            } else if (novel2.getType().equals("玄幻")) {
                a[1]++;
                str[1] = novel2.getType();
            } else if (novel2.getType().equals("武侠")) {
                a[2]++;
                str[2] = novel2.getType();
            } else if (novel2.getType().equals("历史")) {
                a[3]++;
                str[3] = novel2.getType();
            } else if (novel2.getType().equals("奇幻")) {
                a[4]++;
                str[4] = novel2.getType();
            } else if (novel2.getType().equals("仙侠")) {
                a[5]++;
                str[5] = novel2.getType();
            } else if (novel2.getType().equals("现实")) {
                a[6]++;
                str[6] = novel2.getType();
            } else if (novel2.getType().equals("军事")) {
                a[7]++;
                str[7] = novel2.getType();
            } else if (novel2.getType().equals("游戏")) {
                a[8]++;
                str[8] = novel2.getType();
            } else if (novel2.getType().equals("体育")) {
                a[9]++;
                str[9] = novel2.getType();
            } else if (novel2.getType().equals("悬疑")) {
                a[10]++;
                str[10] = novel2.getType();
            } else if (novel2.getType().equals("科幻")) {
                a[11]++;
                str[11] = novel2.getType();
            }
        }
        for (int i = 0; i < 12; i++) {
            typeDtos[i].setValue(a[i]);
            typeDtos[i].setName(str[i]);
            list.add(typeDtos[i]);
        }
        return list;
    }

    public List type2() {
        TypeDto typeDtos[] = new TypeDto[9];
        Query query = new Query();
        String str[] = new String[9];
        int a[] = new int[9];
        for (int i = 0; i < 9; i++) {
            typeDtos[i] = new TypeDto();
            a[i] = 0;
        }
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class, "novel2");
        List<TypeDto> list = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            if (novel2.getType().equals("古代言情")) {
                a[0]++;
                str[0] = novel2.getType();
            } else if (novel2.getType().equals("科幻空间")) {
                a[1]++;
                str[1] = novel2.getType();
            } else if (novel2.getType().equals("浪漫青春")) {
                a[2]++;
                str[2] = novel2.getType();
            } else if (novel2.getType().equals("仙侠奇缘")) {
                a[3]++;
                str[3] = novel2.getType();
            } else if (novel2.getType().equals("现代言情")) {
                a[4]++;
                str[4] = novel2.getType();
            } else if (novel2.getType().equals("现实生活")) {
                a[5]++;
                str[5] = novel2.getType();
            } else if (novel2.getType().equals("玄幻言情")) {
                a[6]++;
                str[6] = novel2.getType();
            } else if (novel2.getType().equals("悬疑推理")) {
                a[7]++;
                str[7] = novel2.getType();
            } else if (novel2.getType().equals("游戏竞技")) {
                a[8]++;
                str[8] = novel2.getType();
            }
        }
        for (int i = 0; i < 9; i++) {
            typeDtos[i].setValue(a[i]);
            typeDtos[i].setName(str[i]);
            list.add(typeDtos[i]);
        }
        return list;
    }

    public List weektui() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.with(Sort.by("weektui").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List novelcount() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.with(Sort.by("novelcount").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List bili1() {
        Query query = new Query();
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class);
        List<BiliDto> biliDto = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            int a = novel2.getWeektui();
            if (a >= 3000) {
                BiliDto biliDto1 = new BiliDto();
                biliDto1.setTotaltui(novel2.getTotaltui());
                biliDto1.setWeektui(novel2.getWeektui());
                biliDto1.setNovelname(novel2.getNovelname());
                biliDto1.setBili(((double) biliDto1.getWeektui() / biliDto1.getTotaltui()) * 100);
                biliDto.add(biliDto1);
//                System.out.println(novel2.getTotaltui());
            }
        }
        return biliDto;
    }

    public List bili2() {
        Query query = new Query();
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class);
        List<Bili2Dto> biliDto = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            int a = novel2.getLeiji();
            if (a > 31370000) {
                Bili2Dto biliDto1 = new Bili2Dto();
                biliDto1.setLeiji(novel2.getLeiji());
                biliDto1.setTotalnovel(novel2.getTotalnovel());
                biliDto1.setAuthor(novel2.getAuthor());
                biliDto1.setBili(((double) biliDto1.getLeiji() / biliDto1.getTotalnovel()));
                biliDto.add(biliDto1);
//                System.out.println(novel2.getTotaltui());
            }
        }
        return biliDto;
    }

    public List fenlei() {
        TypeDto typeDtos[] = new TypeDto[7];
        Query query = new Query();
        String str[] = new String[7];
        int a[] = new int[7];
        for (int i = 0; i < 7; i++) {
            typeDtos[i] = new TypeDto();
            a[i] = 0;
        }
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class, "novel2");
        List<TypeDto> list = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            if (novel2.getNovelcount() < 50000) {
                a[0]++;
                str[0] = "小于五万";
            } else if (novel2.getNovelcount() >= 50000 && novel2.getNovelcount() < 100000) {
                a[1]++;
                str[1] = "五万到十万";
            } else if (novel2.getNovelcount() >= 100000 && novel2.getNovelcount() < 1000000) {
                a[2]++;
                str[2] = "十万到一百万";
            } else if (novel2.getNovelcount() >= 1000000 && novel2.getNovelcount() < 5000000) {
                a[3]++;
                str[3] = "一百万到五百万";
            } else if (novel2.getNovelcount() >= 5000000 && novel2.getNovelcount() < 10000000) {
                a[4]++;
                str[4] = "五百万到一千万";
            } else if (novel2.getNovelcount() >= 10000000 && novel2.getNovelcount() < 20000000) {
                a[5]++;
                str[5] = "一千万到两千万";
            } else if (novel2.getNovelcount() >= 20000000) {
                a[6]++;
                str[6] = "大于两千万";
            }
        }
        for (int i = 0; i < 7; i++) {
            typeDtos[i].setValue(a[i]);
            typeDtos[i].setName(str[i]);
            list.add(typeDtos[i]);
        }
        return list;
    }

    public List bili3() {
        Query query = new Query();
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class);
        List<Bili3Dto> biliDto = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            int a = novel2.getWeektui();
            if (a >= 3000) {
                Bili3Dto biliDto1 = new Bili3Dto();
                biliDto1.setLeiji(novel2.getLeiji());
                biliDto1.setWriteday(novel2.getWriteday());
                biliDto1.setAuthor(novel2.getAuthor());
                biliDto1.setBili(((double) biliDto1.getLeiji() / biliDto1.getWriteday()));
                biliDto.add(biliDto1);
//                System.out.println(novel2.getTotaltui());
            }
        }
        return biliDto;
    }

    public List bili4() {
        Query query = new Query();
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class);
        List<Bili4Dto> biliDto = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            int a = novel2.getNovelcount();
            if (a >= 13800000) {
                Bili4Dto biliDto1 = new Bili4Dto();
                biliDto1.setNovelcount(novel2.getNovelcount());
                biliDto1.setTotaltui(novel2.getTotaltui());
                biliDto1.setNovelname(novel2.getNovelname());
                biliDto1.setBili(((double) biliDto1.getNovelcount() / biliDto1.getTotaltui()));
                biliDto.add(biliDto1);
            }
        }
        return biliDto;
    }

    public List fenxi() {
        FenxiDto typeDtos[] = new FenxiDto[9];
        Query query = new Query();
        String str[] = new String[9];
        int a[] = new int[9];
        String str2[] = new String[9];
        for (int i = 0; i < 9; i++) {
            typeDtos[i] = new FenxiDto();
            a[i] = 0;
        }
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class, "novel2");
        List<FenxiDto> list = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            if (novel2.getType().equals("古代言情") && a[0] < novel2.getNovelcount()) {
                a[0] = novel2.getNovelcount();
                str[0] = novel2.getType();
                str2[0] = novel2.getNovelname();
            } else if (novel2.getType().equals("科幻空间") && a[1] < novel2.getNovelcount()) {
                a[1] = novel2.getNovelcount();
                str[1] = novel2.getType();
                str2[1] = novel2.getNovelname();
            } else if (novel2.getType().equals("浪漫青春") && a[2] < novel2.getNovelcount()) {
                a[2] = novel2.getNovelcount();
                str[2] = novel2.getType();
                str2[2] = novel2.getNovelname();
            } else if (novel2.getType().equals("仙侠奇缘") && a[3] < novel2.getNovelcount()) {
                a[3] = novel2.getNovelcount();
                str[3] = novel2.getType();
                str2[3] = novel2.getNovelname();
            } else if (novel2.getType().equals("现代言情") && a[4] < novel2.getNovelcount()) {
                a[4] = novel2.getNovelcount();
                str[4] = novel2.getType();
                str2[4] = novel2.getNovelname();
            } else if (novel2.getType().equals("现实生活") && a[5] < novel2.getNovelcount()) {
                a[5] = novel2.getNovelcount();
                str[5] = novel2.getType();
                str2[5] = novel2.getNovelname();
            } else if (novel2.getType().equals("玄幻言情") && a[6] < novel2.getNovelcount()) {
                a[6] = novel2.getNovelcount();
                str[6] = novel2.getType();
                str2[6] = novel2.getNovelname();
            } else if (novel2.getType().equals("悬疑推理") && a[7] < novel2.getNovelcount()) {
                a[7] = novel2.getNovelcount();
                str[7] = novel2.getType();
                str2[7] = novel2.getNovelname();
            } else if (novel2.getType().equals("游戏竞技") && a[8] < novel2.getNovelcount()) {
                a[8] = novel2.getNovelcount();
                str[8] = novel2.getType();
                str2[8] = novel2.getNovelname();
            }
        }
        for (int i = 0; i < 9; i++) {
            typeDtos[i].setNovelcount(a[i]);
            typeDtos[i].setType(str[i]);
            typeDtos[i].setNovelname(str2[i]);
            list.add(typeDtos[i]);
        }
        return list;
    }

    public List fenxi2() {
        FenxiDto typeDtos[] = new FenxiDto[12];
        Query query = new Query();
        String str[] = new String[12];
        int a[] = new int[12];
        String str2[] = new String[12];
        for (int i = 0; i < 12; i++) {
            typeDtos[i] = new FenxiDto();
            a[i] = 0;
        }
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class, "novel2");
        List<FenxiDto> list = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            if (novel2.getType().equals("历史") && a[0] < novel2.getNovelcount()) {
                a[0] = novel2.getNovelcount();
                str[0] = novel2.getType();
                str2[0] = novel2.getNovelname();
            } else if (novel2.getType().equals("玄幻") && a[1] < novel2.getNovelcount()) {
                a[1] = novel2.getNovelcount();
                str[1] = novel2.getType();
                str2[1] = novel2.getNovelname();
            } else if (novel2.getType().equals("奇幻") && a[2] < novel2.getNovelcount()) {
                a[2] = novel2.getNovelcount();
                str[2] = novel2.getType();
                str2[2] = novel2.getNovelname();
            } else if (novel2.getType().equals("仙侠") && a[3] < novel2.getNovelcount()) {
                a[3] = novel2.getNovelcount();
                str[3] = novel2.getType();
                str2[3] = novel2.getNovelname();
            } else if (novel2.getType().equals("武侠") && a[4] < novel2.getNovelcount()) {
                a[4] = novel2.getNovelcount();
                str[4] = novel2.getType();
                str2[4] = novel2.getNovelname();
            } else if (novel2.getType().equals("都市") && a[5] < novel2.getNovelcount()) {
                a[5] = novel2.getNovelcount();
                str[5] = novel2.getType();
                str2[5] = novel2.getNovelname();
            } else if (novel2.getType().equals("现实") && a[6] < novel2.getNovelcount()) {
                a[6] = novel2.getNovelcount();
                str[6] = novel2.getType();
                str2[6] = novel2.getNovelname();
            } else if (novel2.getType().equals("军事") && a[7] < novel2.getNovelcount()) {
                a[7] = novel2.getNovelcount();
                str[7] = novel2.getType();
                str2[7] = novel2.getNovelname();
            } else if (novel2.getType().equals("游戏") && a[8] < novel2.getNovelcount()) {
                a[8] = novel2.getNovelcount();
                str[8] = novel2.getType();
                str2[8] = novel2.getNovelname();
            } else if (novel2.getType().equals("体育") && a[9] < novel2.getNovelcount()) {
                a[9] = novel2.getNovelcount();
                str[9] = novel2.getType();
                str2[9] = novel2.getNovelname();
            } else if (novel2.getType().equals("悬疑") && a[10] < novel2.getNovelcount()) {
                a[10] = novel2.getNovelcount();
                str[10] = novel2.getType();
                str2[10] = novel2.getNovelname();
            } else if (novel2.getType().equals("科幻") && a[11] < novel2.getNovelcount()) {
                a[11] = novel2.getNovelcount();
                str[11] = novel2.getType();
                str2[11] = novel2.getNovelname();
            }
        }
        for (int i = 0; i < 12; i++) {
            typeDtos[i].setNovelcount(a[i]);
            typeDtos[i].setType(str[i]);
            typeDtos[i].setNovelname(str2[i]);
            list.add(typeDtos[i]);
        }
        return list;
    }

    public List bili5() {
        Query query = new Query();
        List<Novel2> novel2List = mongoTemplate.find(query, Novel2.class);
        List<Bili5Dto> biliDto = new ArrayList<>();
        for (Novel2 novel2 : novel2List) {
            int a = novel2.getWeektui();
            if (a >= 3000) {
                Bili5Dto biliDto1 = new Bili5Dto();
                biliDto1.setWriteday(novel2.getWriteday());
                biliDto1.setTotalnovel(novel2.getTotalnovel());
                biliDto1.setAuthor(novel2.getAuthor());
                biliDto1.setBili(((double) biliDto1.getWriteday() / biliDto1.getTotalnovel()));
                biliDto.add(biliDto1);
//                System.out.println(novel2.getTotaltui());
            }
        }
        return biliDto;
    }
    public List fenxi3(){
        TypeDto typeDtos[] = new TypeDto[9];
        Query query=new Query();
        String str[] =new String[9];
        int a[]=new int[9];
        int b[]=new int[9];
        for(int i=0;i<9;i++){
            typeDtos[i]=new TypeDto();
            a[i]=0;
            b[i]=0;
        }
        List<Novel2> novel2List = mongoTemplate.find(query,Novel2.class, "novel2");
        List<TypeDto> list = new ArrayList<>();
        for(Novel2 novel2:novel2List){
            if(novel2.getType().equals("古代言情")){
                a[0]+=novel2.getTotaltui();
                b[0]++;
                str[0]=novel2.getType();
            }else if(novel2.getType().equals("科幻空间")){
                a[1]+=novel2.getTotaltui();
                b[1]++;
                str[1]=novel2.getType();
            }else if(novel2.getType().equals("浪漫青春")){
                a[2]+=novel2.getTotaltui();
                b[2]++;
                str[2]=novel2.getType();
            }
            else if(novel2.getType().equals("仙侠奇缘")){
                a[3]+=novel2.getTotaltui();
                b[3]++;
                str[3]=novel2.getType();
            }
            else if(novel2.getType().equals("现代言情")){
                a[4]+=novel2.getTotaltui();
                b[4]++;
                str[4]=novel2.getType();
            }
            else if(novel2.getType().equals("现实生活")){
                a[5]+=novel2.getTotaltui();
                b[5]++;
                str[5]=novel2.getType();
            }
            else if(novel2.getType().equals("玄幻言情")){
                a[6]+=novel2.getTotaltui();
                b[6]++;
                str[6]=novel2.getType();
            }
            else if(novel2.getType().equals("悬疑推理")){
                a[7]+=novel2.getTotaltui();
                b[7]++;
                str[7]=novel2.getType();
            }else if(novel2.getType().equals("游戏竞技")){
                a[8]+=novel2.getTotaltui();
                b[8]++;
                str[8]=novel2.getType();
            }
        }

        for(int i=0;i<9;i++){

            typeDtos[i].setValue(a[i]/b[i]);
            typeDtos[i].setName(str[i]);
            list.add(typeDtos[i]);
        }
        return list;
    }

    public List fenxi4(){
        TypeDto typeDtos[] = new TypeDto[12];
        Query query=new Query();
        String str[] =new String[12];
        int a[]=new int[12];
        int b[]=new int[12];
        for(int i=0;i<12;i++){
            typeDtos[i]=new TypeDto();
            a[i]=0;
            b[i]=0;
        }
        List<Novel2> novel2List = mongoTemplate.find(query,Novel2.class, "novel2");
        List<TypeDto> list = new ArrayList<>();
        for(Novel2 novel2:novel2List){
            if(novel2.getType().equals("历史")){
                a[0]+=novel2.getTotaltui();
                b[0]++;
                str[0]=novel2.getType();
            }else if(novel2.getType().equals("玄幻")){
                a[1]+=novel2.getTotaltui();
                b[1]++;
                str[1]=novel2.getType();
            }else if(novel2.getType().equals("奇幻")){
                a[2]+=novel2.getTotaltui();
                b[2]++;
                str[2]=novel2.getType();
            }
            else if(novel2.getType().equals("武侠")){
                a[3]+=novel2.getTotaltui();
                b[3]++;
                str[3]=novel2.getType();
            }
            else if(novel2.getType().equals("仙侠")){
                a[4]+=novel2.getTotaltui();
                b[4]++;
                str[4]=novel2.getType();
            }
            else if(novel2.getType().equals("现实")){
                a[5]+=novel2.getTotaltui();
                b[5]++;
                str[5]=novel2.getType();
            }
            else if(novel2.getType().equals("游戏")){
                a[6]+=novel2.getTotaltui();
                b[6]++;
                str[6]=novel2.getType();
            }
            else if(novel2.getType().equals("都市")){
                a[7]+=novel2.getTotaltui();
                b[7]++;
                str[7]=novel2.getType();
            }else if(novel2.getType().equals("军事")){
                a[8]+=novel2.getTotaltui();
                b[8]++;
                str[8]=novel2.getType();
            }
            else if(novel2.getType().equals("体育")){
                a[9]+=novel2.getTotaltui();
                b[9]++;
                str[9]=novel2.getType();
            }
            else if(novel2.getType().equals("悬疑")){
                a[10]+=novel2.getTotaltui();
                b[10]++;
                str[10]=novel2.getType();
            }
            else if(novel2.getType().equals("科幻")){
                a[11]+=novel2.getTotaltui();
                b[11]++;
                str[11]=novel2.getType();
            }
        }
        for(int i=0;i<12;i++){

            typeDtos[i].setValue(a[i]/b[i]);
            typeDtos[i].setName(str[i]);
            list.add(typeDtos[i]);
        }
        return list;
    }

    public List fenxi5(){
        TypeDto typeDtos[] = new TypeDto[9];
        Query query=new Query();
        String str[] =new String[9];
        int a[]=new int[9];
        int b[]=new int[9];
        for(int i=0;i<9;i++){
            typeDtos[i]=new TypeDto();
            a[i]=0;
            b[i]=0;
        }
        List<Novel2> novel2List = mongoTemplate.find(query,Novel2.class, "novel2");
        List<TypeDto> list = new ArrayList<>();
        for(Novel2 novel2:novel2List){
            if(novel2.getType().equals("古代言情")){
                a[0]+=novel2.getMonthvote();
                b[0]++;
                str[0]=novel2.getType();
            }else if(novel2.getType().equals("科幻空间")){
                a[1]+=novel2.getMonthvote();
                b[1]++;
                str[1]=novel2.getType();
            }else if(novel2.getType().equals("浪漫青春")){
                a[2]+=novel2.getMonthvote();
                b[2]++;
                str[2]=novel2.getType();
            }
            else if(novel2.getType().equals("仙侠奇缘")){
                a[3]+=novel2.getMonthvote();
                b[3]++;
                str[3]=novel2.getType();
            }
            else if(novel2.getType().equals("现代言情")){
                a[4]+=novel2.getMonthvote();
                b[4]++;
                str[4]=novel2.getType();
            }
            else if(novel2.getType().equals("现实生活")){
                a[5]+=novel2.getMonthvote();
                b[5]++;
                str[5]=novel2.getType();
            }
            else if(novel2.getType().equals("玄幻言情")){
                a[6]+=novel2.getMonthvote();
                b[6]++;
                str[6]=novel2.getType();
            }
            else if(novel2.getType().equals("悬疑推理")){
                a[7]+=novel2.getMonthvote();
                b[7]++;
                str[7]=novel2.getType();
            }else if(novel2.getType().equals("游戏竞技")){
                a[8]+=novel2.getMonthvote();
                b[8]++;
                str[8]=novel2.getType();
            }
        }

        for(int i=0;i<9;i++){

            typeDtos[i].setValue(a[i]/b[i]);
            typeDtos[i].setName(str[i]);
            list.add(typeDtos[i]);
        }
        return list;
    }

    public List fenxi6(){
        TypeDto typeDtos[] = new TypeDto[12];
        Query query=new Query();
        String str[] =new String[12];
        int a[]=new int[12];
        int b[]=new int[12];
        for(int i=0;i<12;i++){
            typeDtos[i]=new TypeDto();
            a[i]=0;
            b[i]=0;
        }
        List<Novel2> novel2List = mongoTemplate.find(query,Novel2.class, "novel2");
        List<TypeDto> list = new ArrayList<>();
        for(Novel2 novel2:novel2List){
            if(novel2.getType().equals("历史")){
                a[0]+=novel2.getMonthvote();
                b[0]++;
                str[0]=novel2.getType();
            }else if(novel2.getType().equals("玄幻")){
                a[1]+=novel2.getMonthvote();
                b[1]++;
                str[1]=novel2.getType();
            }else if(novel2.getType().equals("奇幻")){
                a[2]+=novel2.getMonthvote();
                b[2]++;
                str[2]=novel2.getType();
            }
            else if(novel2.getType().equals("武侠")){
                a[3]+=novel2.getMonthvote();
                b[3]++;
                str[3]=novel2.getType();
            }
            else if(novel2.getType().equals("仙侠")){
                a[4]+=novel2.getMonthvote();
                b[4]++;
                str[4]=novel2.getType();
            }
            else if(novel2.getType().equals("现实")){
                a[5]+=novel2.getMonthvote();
                b[5]++;
                str[5]=novel2.getType();
            }
            else if(novel2.getType().equals("游戏")){
                a[6]+=novel2.getMonthvote();
                b[6]++;
                str[6]=novel2.getType();
            }
            else if(novel2.getType().equals("都市")){
                a[7]+=novel2.getMonthvote();
                b[7]++;
                str[7]=novel2.getType();
            }else if(novel2.getType().equals("军事")){
                a[8]+=novel2.getMonthvote();
                b[8]++;
                str[8]=novel2.getType();
            }
            else if(novel2.getType().equals("体育")){
                a[9]+=novel2.getMonthvote();
                b[9]++;
                str[9]=novel2.getType();
            }
            else if(novel2.getType().equals("悬疑")){
                a[10]+=novel2.getMonthvote();
                b[10]++;
                str[10]=novel2.getType();
            }
            else if(novel2.getType().equals("科幻")){
                a[11]+=novel2.getMonthvote();
                b[11]++;
                str[11]=novel2.getType();
            }
        }
        for(int i=0;i<12;i++){

            typeDtos[i].setValue(a[i]/b[i]);
            typeDtos[i].setName(str[i]);
            list.add(typeDtos[i]);
        }
        return list;
    }
    public List<Novel2> xuanhuan() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.addCriteria(Criteria.where("type").is("玄幻"));
        query.with(Sort.by("totaltui").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List<Novel2> xianxia() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.addCriteria(Criteria.where("type").is("仙侠"));
        query.with(Sort.by("weektui").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List<Novel2> lishi() {
        Query query = new Query();
        int limit = 10;
        query.limit(limit);
        query.addCriteria(Criteria.where("type").is("历史"));
        query.with(Sort.by("reward").descending());
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List<Novel2> gudai() {
        Query query = new Query();
        query.addCriteria(Criteria.where("type").is("古代言情"));
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List<Novel2> wuxia() {
        Query query = new Query();
        query.addCriteria(Criteria.where("type").is("武侠"));
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List<Novel2> kehuan() {
        Query query = new Query();
        query.addCriteria(Criteria.where("type").is("科幻"));
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }

    public List<Novel2> yanqing() {
        Query query = new Query();
        query.addCriteria(Criteria.where("type").is("玄幻言情"));
        List<Novel2> novelList = mongoTemplate.find(query, Novel2.class, "novel2");
        return novelList;
    }
}